//
//  modifyPassViewController.m
//  ZhenPin
//
//  Created by tmosport on 14-7-21.
//  Copyright (c) 2014年 zhenpin. All rights reserved.
//

#import "modifyPassViewController.h"
#import "MBProgressHUD.h"
@interface modifyPassViewController ()
{
    MBProgressHUD *hud;
}
@property(nonatomic,strong)NSString *mobile;
@end

@implementation modifyPassViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"修改密码";
    [self setNavigationItem];
    NSString *homePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/UserInfo.plist"];
    NSMutableDictionary *dataDic = [[NSDictionary dictionaryWithContentsOfFile:homePath] mutableCopy];
    _mobile = [dataDic valueForKey:@"mobile"];
    if ([_mobile length] == 0 ||[_mobile isEqual:[NSNull null]]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"此功能暂不支持非手机注册用户" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alert show];
        return;
    }
    NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://m.zhenpin.com/?c=APP_member&a=upMyPassShow&mobile=%@&memberid=%@&token=%@",_mobile,_memberId,_token]];
    [_modifyPassWebView loadRequest:[NSURLRequest requestWithURL:url]];
    
}

-(void)setNavigationItem {
    [self.navigationController.navigationBar setBackIndicatorImage:
     [UIImage imageNamed:@"return"]];
    [self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:
     [UIImage imageNamed:@"return"]];
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
}

-(void)leftBarbuttonItemClicked:(UIButton *)button {
    [self.navigationController popViewControllerAnimated:YES];
}



//AlertView的协议方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    BOOL canbe;
    NSURL *url = [request URL];
    if ([[url scheme] isEqualToString:@"zpmall"]) {
        [self goHome];
    }
    if ([_mobile length] == 0 ||[_mobile isEqual:[NSNull null]]) {
        canbe =  NO;
    }else{
        canbe = YES;
    }
    return canbe;
}

-(void)goHome{
    [self.navigationController popToRootViewControllerAnimated:NO];
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = @"正在加载中";
    hud.dimBackground = YES;
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
//    hud.labelText = @"加载完成";
    [hud hide:YES ];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    hud.labelText = @"加载失败";
    [hud hide:YES afterDelay:1];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
